package edu.suda.xsap.controller;

import edu.suda.xsap.dto.EmployeeCourseDto;
import edu.suda.xsap.mapper.EmployeeCourseMapper;
import edu.suda.xsap.service.EmployeeCourseService;
import edu.suda.xsap.service.EmployeeService;
import edu.suda.xsapadminutils.common.Result;
import edu.suda.xsapadminvo.EmployeeCourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employeeCourse")
public class EmployeeCourseController {
    @Autowired
    private EmployeeCourseService employeeCourseService;
    @Autowired
    private EmployeeService employeeService;


    @PostMapping("/save")
    public Result save(@RequestBody EmployeeCourseVO employeeCourseVO) {
        Integer employeeId = employeeService.findByName(employeeCourseVO.getName());
        employeeCourseVO.setEmployeeId(employeeId);
        return employeeCourseService.save(employeeCourseVO);
    }

    @GetMapping("/findAll")
    public List<EmployeeCourseDto> findAll() {
        return employeeCourseService.findAll();
    }

}
